<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/3/22
 * Time: 上午11:49
 */
class LoginController extends AdminBaseController {

    public function index(){
        $this->setTitle('活跃报表');

        $filter = new PubFilter('pl');
        $chart  = new PubChart();
        $grid   = new PubGrid();

        $lod_special_id = $this->R('special_id');
		$lodos = $this->R('os');
		$filter->addSpecialFilter(false,2);
		$filter->addOsFilter($lod_special_id,true,2)
        ->addServerFilter($lod_special_id,$lodos,true,false,2)
            ->addFilter('time_start', 'input', PubFunc::t('时间'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-7 day'))),2)
            ->addFilter('time_end', 'input', PubFunc::t('至'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))),2)
            ->addExport();

        $params = $filter->get();

        $params = $this->indexCommon($params);

        $header = LoginService::header($params);
        $data   = LoginService::data($params);

        if($filter->isExport()){
            $filename = LibExcel::getFilename('活跃报表', $params);
            LibExcel::exportCsv($header, $data, $filename);
        }else{
            $grid->addGrid($header, $data, array(
                'order' => array('RecDate', 'desc'),
            	'fix'   => array(
            			'col' => 1
            	)
            ));

            $chartConfig = LoginService::chart($data, $params);
            $chart->addChart('chart', $chartConfig['data'], array(
                'name'   => $params['time_start'].'~'.$params['time_end'].PubFunc::t('用户活跃报表'),
                'config' => $chartConfig['config']
            ));

            $this->out['filter']    = $filter->show();
            $this->out['grid']      = $grid->show();
            $this->out['chart']     = $chart->show();
            $this->out['is_ana'] = 2;

        }
    }

}